﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
namespace JustMoveIt.Logic
{
    class Logger
    {
        private ILog log;
        private const string Linebreak = "--------------------------------------------------------";
        private const string Indent = "\t\t\t";
        private static Logger _instance;
        public static Logger Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new Logger();
                }
                return _instance;
            }

        }
        private Logger()
        {
            log = LogManager.GetLogger("debug");
        }

        public void Write(Object message)
        {
            if (message is Exception)
            {
                Exception e = message as Exception;
                StringBuilder builder = new StringBuilder();
                builder.AppendLine("\tException Caught");
                builder.Append(Indent);
                builder.AppendLine(Linebreak);
                builder.Append(Indent);
                builder.AppendLine(e.GetType().FullName);
                builder.AppendLine("\n");
                builder.Append(Indent);
                string[] stacktraces = e.ToString().Split(new char[] { '\n' });
                foreach (string trace in stacktraces)
                {
                    builder.Append(Indent);
                    builder.AppendLine(trace);
                }
                builder.Append(Indent);
                builder.AppendLine(Linebreak);
                log.Info(builder.ToString());
            }
            else if(message is string)
            {
                string s = message as string;
                log.Info(s);
            }
        }
    }
}
